home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / misc / gms_dev.lha / GMSDev / Source / Asm / Chunky / 000.CPU1.s next >
Encoding:
Text File  |  1998-03-16  |  13.0 KB  |  515 lines

  1. ;===================================================================================;
  2. ;                                 CHUNKY8 EMULATOR
  3. ;===================================================================================;
  4. ;This c2p routine is also used in the rtgmaster library, it's not too bad for
  5. ;a CPU only routine.
  6.  
  7. CHUNKYMEM =    MEM_DATA    ;<- Fast memory.
  8.  
  9.     INCDIR    "INCLUDES:"
  10.     INCLUDE    "exec/libraries.i"
  11.     INCLUDE    "exec/initializers.i"
  12.     INCLUDE    "exec/resident.i"
  13.     INCLUDE    "exec/exec_lib.i"
  14.     INCLUDE    "hardware/custom.i"
  15.     INCLUDE    "dpkernel/dpkernel.i"
  16.     INCLUDE    "system/debug.i"
  17.  
  18. CALL    MACRO
  19.     jsr    _LVO\1(a6)
  20.     ENDM
  21.  
  22. ;===================================================================================;
  23. ;                                  MONITOR DRIVER
  24. ;===================================================================================;
  25.  
  26.     STRUCTURE    ChunkyBase,LIB_SIZE
  27.     ULONG    CHK_SegList
  28.     LABEL    CHKBase_SIZEOF
  29.  
  30.     SECTION    "Chunky8",CODE
  31.  
  32. LibPriority =     0
  33.  
  34. CleanExit:        ;If the user tries to run the library, we
  35.     moveq    #$00,d0    ;don't want to crash...
  36.     rts
  37.  
  38. InitDescrip:
  39.     dc.w    RTC_MATCHWORD    ;UWORD rt_matchword
  40.     dc.l    InitDescrip,EndCode    ;APTR  rt_matchtag, rt_endskip
  41.     dc.b    RTF_AUTOINIT,DPKVersion    ;UBYTE rt_flags, rt_version
  42.     dc.b    NT_LIBRARY,LibPriority    ;UBYTE rt_type, rt_pri
  43.     dc.l    LibName,IDString,Init    ;APTR  rt_name, rt_idstring, rt_init
  44.  
  45. LibName:
  46.     dc.b    "000.CPU1",0
  47.     even
  48.     dc.b    "$VER: "
  49. IDString:
  50.     dc.b    "Chunky 8 Emulator V1.0",10,0
  51.     even
  52.  
  53. Init:    dc.l    CHKBase_SIZEOF,FunctionTable,DataTable,InitRoutine
  54.  
  55. FunctionTable:
  56. FT:    dc.w    -1,Open-FT,Close-FT,Expunge-FT,Null-FT
  57.     dc.w    LIB_emuStart-FT
  58.     dc.w    LIB_emuInitRefresh-FT
  59.     dc.w    LIB_emuFreeRefresh-FT
  60.     dc.w    LIB_emuRefreshScreen-FT
  61.     dc.w    -1
  62.  
  63. DataTable:
  64.     INITBYTE LN_TYPE,NT_LIBRARY
  65.     INITLONG LN_NAME,LibName
  66.     INITBYTE LIB_FLAGS,LIBF_SUMUSED!LIBF_CHANGED
  67.     INITWORD LIB_VERSION,DPKVersion
  68.     INITWORD LIB_REVISION,DPKRevision
  69.     INITLONG LIB_IDSTRING,IDString
  70.     dc.l    0
  71.     even
  72.  
  73. ;===================================================================================;
  74. ;                              INITIALISATION ROUTINE
  75. ;===================================================================================;
  76. ;Requires: a0 = SegList
  77. ;       d0 = Library Base.
  78.  
  79. InitRoutine:
  80.     MOVEM.L    D1-D7/A0-A6,-(SP)    ;SP = Save registers.
  81.     move.l    d0,a5    ;a5 = Store pointer to our base.
  82.     move.l    d0,CHKBase    ;ma = Save pointer to our base.
  83.     move.l    a0,CHK_SegList(a5)    ;a5 = Save pointer to SegList.
  84.     move.l    CHKBase(pc),d0    ;d0 = Return library pointer.
  85. .error    MOVEM.L    (SP)+,D1-D7/A0-A6    ;SP = Return registers.
  86.     rts
  87.  
  88. ;===================================================================================;
  89. ;                                   OPEN LIBRARY
  90. ;===================================================================================;
  91.  
  92. Open:    addq.w    #1,LIB_OPENCNT(a6)    ;Increment lib count.
  93.     bclr    #LIBB_DELEXP,LIB_FLAGS(a6)
  94.     move.l    a6,d0    ;Return library base.
  95.     rts
  96.  
  97. ;===================================================================================;
  98. ;                                  CLOSE LIBRARY
  99. ;===================================================================================;
  100.  
  101. Close:    moveq    #$00,d0    ;This is called whenever someone closes
  102.     subq.w    #1,LIB_OPENCNT(a6)    ;our library.
  103.     bne.s    .Exit
  104.     btst    #LIBB_DELEXP,LIB_FLAGS(a6)
  105.     beq.s    .Exit
  106.     bsr.s    Expunge
  107. .Exit    rts
  108.  
  109. ;===================================================================================;
  110. ;                               EXPUNGE THE LIBRARY
  111. ;===================================================================================;
  112.  
  113. Expunge:
  114.     MOVEM.L    D1-D7/A0-A6,-(SP)    ;SP = Save all registers.
  115.     move.l    a6,a5    ;a5 = Our library base.
  116.     tst.w    LIB_OPENCNT(a5)    ;a5 = Do any programs have us open?
  117.     beq.s    .expunge    ;>> = No, so it's safe to expunge ourselves.
  118.     bset    #LIBB_DELEXP,LIB_FLAGS(a5)
  119.     MOVEM.L    (SP)+,D1-D7/A0-A6    ;SP = Return all registers.
  120.     moveq    #$00,d0
  121.     rts
  122.  
  123. .expunge
  124.     move.l    ($4).w,a6    ;a6 = ExecBase.
  125.     move.l    CHK_SegList(a5),d2    ;d2 = Our segment list.
  126.     move.l    a5,a1    ;a1 = Our library base.
  127.     CALL    Remove    ;>> = Remove it.
  128.     move.l    a5,a1    ;a1 = Our library base.
  129.     moveq    #$00,d0    ;d0 = 00
  130.     move.w    LIB_NEGSIZE(a5),d0    ;d0 = LIB_NEGSIZE(base)
  131.     sub.l    d0,a1    ;a1 = (base)-LIB_NEGSIZE
  132.     add.w    LIB_POSSIZE(a5),d0    ;d0 = (LIB_NEGSIZE)+LIB_POSSIZE
  133.     CALL    FreeMem    ;>> = Free the memory.
  134.     move.l    d2,d0    ;d0 = Pointer to segment list.
  135.     MOVEM.L    (SP)+,D1-D7/A0-A6    ;SP = Return all registers, d0 = seglist.
  136.     rts
  137.  
  138. ;===================================================================================;
  139. ;                                    DO NOTHING
  140. ;===================================================================================;
  141.  
  142. Null:    moveq    #$00,d0
  143.     rts
  144.  
  145. ;===================================================================================;
  146. ;                                FUNCTION REMAPPING
  147. ;===================================================================================;
  148. ;Function: Ignore this function, we will only use it to grab the DPKBase.
  149. ;Requires: d0 = DPKBase.
  150. ;       a6 = Chunky Base.
  151. ;Returns:  d0 = ErrorCode
  152.  
  153. LIB_emuStart:
  154.     move.l    d0,DPKBase    ;ma = Save the DPKBase.
  155.     moveq    #ERR_OK,d0    ;d0 = No errors.
  156.     rts
  157.  
  158. ;===================================================================================;
  159. ;                             INITIALISE C2P ALGORITHM
  160. ;===================================================================================;
  161. ;Function: Initialise the C2P algorithm for emuRefreshScreen().  Note how if the
  162. ;       screen is double buffered, we do not allocate a second chunky buffer.
  163. ;       The reason is a second planar display buffer already exists, so
  164. ;       having a two chunky buffers has no benefit.
  165. ;
  166. ;Requires: a0 = Screen
  167. ;Returns:  d0 = ErrorCode.
  168.  
  169. LIB_emuInitRefresh:
  170.     MOVEM.L    D2-D7/A2-A6,-(SP)    ;SP = Return used registers.
  171.     move.l    a0,a3
  172.     move.l    GS_Bitmap(a3),a4    ;a4 = Bitmap structure.
  173.     cmp.l    #$00,a4
  174.     beq.s    .error
  175.  
  176.     ;Move the planar screen displays (allocated in AddScreen()) to
  177.     ;GS_EMemPtrX.
  178.  
  179.     move.l    GS_MemPtr1(a3),GS_EMemPtr1(a3)    ;a3 = Save planar.
  180.     move.l    GS_MemPtr2(a3),GS_EMemPtr2(a3)    ;a3 = Save planar.
  181.     move.l    GS_MemPtr3(a3),GS_EMemPtr3(a3)    ;a3 = Save planar.
  182.     clr.l    GS_MemPtr1(a3)        ;a3 = Clear record pf memory ptr.
  183.     clr.l    GS_MemPtr2(a3)        ;a3 = Clear record of memory ptr.
  184.     clr.l    GS_MemPtr3(a3)        ;a3 = Clear record of memory ptr.
  185.  
  186.     ;Allocate the chunky memory, place it in GS_MemPtrX fields and store
  187.     ;the pointers in GS_EFreeX fields to free it later.
  188.  
  189.     move.l    DPKBase(pc),a6    ;a6 = DPKBase.
  190.     move.w    BMP_Width(a4),d0    ;d0 = BmpWidth
  191.     mulu    BMP_Height(a4),d0    ;d0 = (BmpWidth)*BmpHeight
  192.     moveq    #CHUNKYMEM,d1    ;d1 = Memory Type (see definition).
  193.     CALL    AllocMemBlock    ;>> = Go get the chunky memory.
  194.     move.l    d0,GS_EFree1(a3)    ;a3 = Store chunky buffer for freemem.
  195.     move.l    d0,GS_MemPtr1(a3)    ;a3 = Store chunky buffer in ptr #1.
  196.     beq.s    .error    ;>> = Memory allocation error.
  197.  
  198.     move.l    GS_Attrib(a3),d2    ;d2 = Screen attributes.
  199.     and.l    #SCR_DBLBUFFER|SCR_TPLBUFFER,d2    ;d2 = Double/Triple buffer?
  200.     beq.s    .done    ;>> = No, finished.
  201.     move.l    d0,GS_MemPtr2(a3)    ;a3 = Store chunky buffer in ptr #2.
  202.  
  203.     move.l    GS_Attrib(a3),d2    ;d2 = Screen attributes.
  204.     and.l    #SCR_TPLBUFFER,d2    ;d2 = Triple buffer?
  205.     beq.s    .done    ;>> = Done.
  206.     move.l    d0,GS_MemPtr3(a3)    ;a3 = Store chunky buffer in ptr #3.
  207.     
  208. .done    move.l    GS_MemPtr1(a3),BMP_Data(a4)
  209.     MOVEM.L    (SP)+,D2-D7/A2-A6    ;SP = Return used registers.
  210.     moveq    #ERR_OK,d0    ;d0 = No errors.
  211.     rts
  212.  
  213. .error    MOVEM.L    (SP)+,D2-D7/A2-A6    ;SP = Return used registers.
  214.     moveq    #ERR_FAILED,d0    ;d0 = Failure.
  215.     rts
  216.  
  217. ;===================================================================================;
  218. ;                               REMOVE C2P ALGORITHM
  219. ;===================================================================================;
  220. ;Function: Free any allocations we made for the C2P routine.
  221. ;Requires: a0 = Screen
  222. ;       a6 = Chunky Base.
  223. ;Returns:  Nothing.
  224.  
  225. LIB_emuFreeRefresh:
  226.     MOVEM.L    D0/A6,-(SP)    ;SP = Save used registers.
  227.     move.l    DPKBase(pc),a6    ;a6 = DPKBase.
  228.     move.l    GS_EFree1(a0),d0    ;d0 = Screen memory 1 (C2P)
  229.     CALL    FreeMemBlock    ;>> = Free screen memory.
  230.     move.l    GS_EFree2(a0),d0    ;d0 = Screen memory 2 (C2P)
  231.     CALL    FreeMemBlock    ;>> = Free screen memory.
  232.     move.l    GS_EFree3(a0),d0    ;d0 = Screen memory 3 (C2P)
  233.     CALL    FreeMemBlock    ;>> = Free screen memory.
  234.     MOVEM.L    (SP)+,D0/A6    ;SP = Return used registers.
  235.     rts
  236.  
  237. ;===================================================================================;
  238. ;                              C2P CONVERSION ROUTINE
  239. ;===================================================================================;
  240. ;Function: Do the C2P process.
  241. ;Requires: a0 = Screen
  242. ;       a6 = Chunky Base.
  243. ;Returns:  Nothing.
  244.  
  245. LIB_emuRefreshScreen:
  246.     MOVEM.L    D0-D7/A0-A6,-(SP)    ;SP = Save used registers.
  247.     move.l    GS_Bitmap(a0),a4
  248.     moveq    #$00,d0    ;d0 = 00.
  249.     moveq    #$00,d1    ;d1 = 00.
  250.     move.w    BMP_Width(a4),d0    ;d0 = Width.
  251.     move.w    BMP_Height(a4),d1    ;d1 = Height.
  252.     move.l    d0,d2    ;d2 = ByteWidth
  253.     lsr.l    #3,d2    ;d2 = (ByteWidth)/8 [planar]
  254.     move.l    d2,d3    ;d3 = Line modulo.
  255.     mulu    BMP_Height(a4),d2    ;d2 = (ByteWidth/8)*Height
  256.  
  257.     move.l    GS_Attrib(a0),d7    ;d7 = Screen attributes
  258.     and.l    #SCR_DBLBUFFER|SCR_TPLBUFFER,d7    ;d7 = Double or triple buffered?
  259.     bne.s    .doubleandtriple    :>> = Yes.
  260. .single    move.l    GS_EMemPtr1(a0),a1    ;a1 = Pointer to planar display.
  261.     move.l    GS_MemPtr1(a0),a0    ;a0 = Pointer to chunky buffer.
  262.     bra.s    .process
  263.  
  264. .doubleandtriple
  265.     move.l    GS_EMemPtr2(a0),a1    ;a1 = Pointer to planar display.
  266.     move.l    GS_MemPtr2(a0),a0    ;a0 = Pointer to chunky buffer.
  267.  
  268.     ;a0 = Chunky buffer.
  269.     ;a1 = First bitplane.
  270.     ;d0 = Width in pixels, multiple of 32.
  271.     ;d1 = Height in pixels (even).
  272.     ;d2 = Bitplane modulo.
  273.     ;d3 = Line modulo. Modulo from start of one line to start of next (linemod)
  274.  
  275. .process
  276.     move.l    d2,a5    ;a5 = Plane Size.
  277.     lsl.l    #3,d2    ;d2 = (PlaneSize)*8
  278.     sub.l    a5,d2    ;d2 = (PlaneSize*8)-PlaneSize
  279.     subq.l    #2,d2    ;d2 = --2
  280.     move.l    d2,a6    ;a6 = (PlaneSize*8-PlaneSize-2)
  281.     lsr.w    #4,d0    ;d0 = Width/32
  282.     ext.l    d0    ;d0 = Make long.
  283.     move.l    d0,d4    ;d4 = Width/32
  284.     subq.l    #1,d4    ;d4 = (Width/32)-1
  285.     move.l    d4,-(SP)    ;SP = Save it.
  286.     add.l    d0,d0    ;d0 = (Width/32)*2
  287.     sub.l    d0,d3    ;d3 = (LineMod)-Width/16
  288.     sub.l    a6,d3    ;d3 =
  289.     move.l    d3,-(SP)    ;SP =
  290.     move.w    d1,d7    ;d7 = Height
  291.     subq.w    #1,d7    ;d7 = (Height)-1 [for loop]
  292.     movea.l    #$f0f0f0f0,a2    ;a2 = $F0F0F0F0
  293.     movea.l    #$cccccccc,a3    ;a3 = $CCCCCCCC
  294.     movea.l    #$aaaa5555,a4    ;a4 = $AAAA5555
  295.     move.l    a2,d6    ;d6 = $F0F0F0F0
  296.     swap    d7    ;d7 = (loop)<<16
  297.     move.w    (6,SP),d7
  298.     move.l    (a0)+,d0
  299.     move.l    (a0)+,d1
  300.     move.l    (a0)+,d2
  301.     move.l    (a0)+,d3
  302.     move.l    d0,d4
  303.     and.l    d6,d0
  304.     eor.l    d0,d4
  305.     lsl.l    #4,d4
  306.     bra    .same
  307.  
  308. .outer    swap    d7
  309.     move.w    (6,sp),d7
  310.     move.w    d5,(a1)
  311.     adda.l    a5,a1
  312.     swap    d5
  313.     move.w    d5,(a1)
  314.     adda.l    (sp),a1
  315.     movem.l    (a0)+,d0-d3
  316.     move.l    d0,d5
  317.     swap    d0
  318.     rol.l    #8,d2
  319.     move.w    d0,d4
  320.     move.b    d2,d4
  321.     swap    d4
  322.     swap    d2
  323.     move.w    d2,d4
  324.     move.b    d0,d4
  325.     ror.w    #8,d4
  326.     move.b    d2,d5
  327.     swap    d5
  328.     swap    d2
  329.     move.w    d2,d5
  330.     swap    d0
  331.     move.b    d0,d5
  332.     ror.w    #8,d5
  333.     move.l    d1,d2
  334.     swap    d1
  335.     rol.l    #8,d3
  336.     move.w    d1,d0
  337.     move.b    d3,d0
  338.     swap    d0
  339.     swap    d3
  340.     move.w    d3,d0
  341.     move.b    d1,d0
  342.     ror.w    #8,d0
  343.     move.b    d3,d2
  344.     swap    d2
  345.     swap    d3
  346.     move.w    d3,d2
  347.     swap    d1
  348.     move.b    d1,d2
  349.     ror.w    #8,d2
  350.     move.l    d2,d3
  351.     move.l    d0,d2
  352.     move.l    d4,d0
  353.     move.l    d5,d1
  354.     move.l    d0,d4
  355.     and.l    d6,d0
  356.     eor.l    d0,d4
  357.     lsl.l    #4,d4
  358.     bra.s    .same
  359.  
  360. .inner    move.w    d5,(a1)
  361.     adda.l    a5,a1
  362.     swap    d5
  363.     move.w    d5,(a1)
  364.     suba.l    a6,a1
  365.     move.l    (a0)+,d0
  366.     move.l    d0,d5
  367.     move.l    (a0)+,d1
  368.     swap    d0
  369.     move.l    (a0)+,d2
  370.     rol.l    #8,d2
  371.     move.w    d0,d4
  372.     move.b    d2,d4
  373.     swap    d4
  374.     swap    d2
  375.     move.w    d2,d4
  376.     move.b    d0,d4
  377.     ror.w    #8,d4
  378.     move.b    d2,d5
  379.     swap    d5
  380.     swap    d2
  381.     move.w    d2,d5
  382.     swap    d0
  383.     move.b    d0,d5
  384.     ror.w    #8,d5
  385.     move.l    d1,d2
  386.     swap    d1
  387.     move.l    (a0)+,d3
  388.     rol.l    #8,d3
  389.     move.w    d1,d0
  390.     move.b    d3,d0
  391.     swap    d0
  392.     swap    d3
  393.     move.w    d3,d0
  394.     move.b    d1,d0
  395.     ror.w    #8,d0
  396.     move.b    d3,d2
  397.     swap    d2
  398.     swap    d3
  399.     move.w    d3,d2
  400.     swap    d1
  401.     move.b    d1,d2
  402.     ror.w    #8,d2
  403.     move.l    d2,d3
  404.     move.l    d0,d2
  405.     move.l    d4,d0
  406.     move.l    d5,d1
  407.     and.l    d6,d0
  408.     eor.l    d0,d4
  409.     lsl.l    #4,d4
  410.  
  411. .same    move.l    d2,d5
  412.     and.l    d6,d5
  413.     eor.l    d5,d2
  414.     lsr.l    #4,d5
  415.     or.l    d5,d0
  416.     or.l    d4,d2
  417.     move.l    d1,d4
  418.     and.l    d6,d1
  419.     eor.l    d1,d4
  420.     move.l    d3,d5
  421.     and.l    d6,d5
  422.     eor.l    d5,d3
  423.     lsr.l    #4,d5
  424.     lsl.l    #4,d4
  425.     or.l    d5,d1
  426.     or.l    d4,d3
  427.     move.l    a3,d6
  428.     move.l    d2,d4
  429.     and.l    d6,d2
  430.     eor.l    d2,d4
  431.     move.l    d3,d5
  432.     and.l    d6,d5
  433.     eor.l    d5,d3
  434.     lsl.l    #2,d4
  435.     or.l    d4,d3
  436.     move.l    a4,d6
  437.     move.l    d3,d4
  438.     and.l    d6,d3
  439.     eor.l    d3,d4
  440.     lsr.w    #1,d4
  441.     swap    d4
  442.     add.w    d4,d4
  443.     or.l    d4,d3
  444.     move.w    d3,(a1)
  445.     adda.l    a5,a1
  446.     lsr.l    #2,d5
  447.     or.l    d5,d2
  448.     move.l    d2,d4
  449.     and.l    d6,d2
  450.     eor.l    d2,d4
  451.     lsr.w    #1,d4
  452.     swap    d3
  453.     move.w    d3,(a1)
  454.     adda.l    a5,a1
  455.     swap    d4
  456.     add.w    d4,d4
  457.     or.l    d4,d2
  458.     move.l    a3,d6
  459.     move.l    d0,d4
  460.     and.l    d6,d0
  461.     eor.l    d0,d4
  462.     move.w    d2,(a1)
  463.     adda.l    a5,a1
  464.     move.l    d1,d5
  465.     and.l    d6,d5
  466.     eor.l    d5,d1
  467.     lsl.l    #2,d4
  468.     or.l    d4,d1
  469.     move.l    a4,d6
  470.     swap    d2
  471.     move.w    d2,(a1)
  472.     adda.l    a5,a1
  473.     move.l    d1,d4
  474.     and.l    d6,d1
  475.     eor.l    d1,d4
  476.     lsr.w    #1,d4
  477.     swap    d4
  478.     add.w    d4,d4
  479.     or.l    d4,d1
  480.     move.w    d1,(a1)
  481.     adda.l    a5,a1
  482.     lsr.l    #2,d5
  483.     or.l    d5,d0
  484.     move.l    d0,d5
  485.     and.l    d6,d0
  486.     eor.l    d0,d5
  487.     swap    d1
  488.     move.w    d1,(a1)
  489.     adda.l    a5,a1
  490.     lsr.w    #1,d5
  491.     swap    d5
  492.     add.w    d5,d5
  493.     or.l    d0,d5
  494.     move.l    a2,d6
  495.     dbra    d7,.inner
  496.     swap    d7
  497.     dbra    d7,.outer
  498.     move.w    d5,(a1)
  499.     adda.l    a5,a1
  500.     swap    d5
  501.     move.w    d5,(a1)
  502.     addq.l    #8,sp
  503.     MOVEM.L    (SP)+,D0-D7/A0-A6    ;SP = Return used registers.
  504.     rts
  505.  
  506. ;===================================================================================;
  507. ;                                       DATA
  508. ;===================================================================================;
  509.  
  510. DPKBase    dc.l    0
  511. CHKBase dc.l    0
  512.  
  513. ;-----------------------------------------------------------------------------------;
  514. EndCode:
  515.